export interface Counselor {
  id: number;
  name: string;
  gender: string;
  phone: string;
  email: string;
  department: string;
  position: string;
  hireDate: string;
  status: boolean;
  classes?: string[]; // 所带班级
  studentCount?: number; // 所带班级总人数
}

// mock数据
export const mockCounselorData: Counselor[] = [
  {
    id: 1,
    name: '张三',
    gender: '男',
    phone: '13800138001',
    email: 'zhangsan@example.com',
    department: '计算机学院',
    position: '辅导员',
    hireDate: '2020-09-01',
    status: true,
    classes: ['2405A'],
    studentCount: 85
  },
  {
    id: 2,
    name: '李四',
    gender: '女',
    phone: '13800138002',
    email: 'lisi@example.com',
    department: '电子工程学院',
    position: '辅导员',
    hireDate: '2021-03-15',
    status: true,
    classes: ['2405B'],
    studentCount: 78
  },
  {
    id: 3,
    name: '王五',
    gender: '男',
    phone: '13800138003',
    email: 'wangwu@example.com',
    department: '机械工程学院',
    position: '辅导员',
    hireDate: '2019-07-01',
    status: false,
    classes: ['2405C'],

    studentCount: 42
  },
  {
    id: 4,
    name: '赵六',
    gender: '女',
    phone: '13800138004',
    email: 'zhaoliu@example.com',
    department: '金融管理',
    position: '辅导员',
    hireDate: '2022-01-10',
    status: true,
    classes: ['2407D'],

    studentCount: 115
  },
  {
    id: 5,
    name: '钱七',
    gender: '男',
    phone: '13800138005',
    email: 'qianqi@example.com',
    department: '网站工程',
    position: '辅导员',
    hireDate: '2020-05-20',
    status: true,
    classes: ['2407E'],

    studentCount: 72
  },
  {
    id: 6,
    name: '孙八',
    gender: '女',
    phone: '13800138006',
    email: 'sunba@example.com',
    department: '数据分析',
    position: '辅导员',
    hireDate: '2021-09-01',
    status: true,
    classes: ['2408A'],
    studentCount: 68
  },
  {
    id: 7,
    name: '周九',
    gender: '男',
    phone: '13800138007',
    email: 'zhoujiu@example.com',
    department: '新媒体学院',
    position: '辅导员',
    hireDate: '2018-11-11',
    status: false,
    classes: ['2408B'],

    studentCount: 92
  },
  {
    id: 8,
    name: '吴十',
    gender: '女',
    phone: '13800138008',
    email: 'wushi@example.com',
    department: '人工智能学院',
    position: '辅导员',
    hireDate: '2022-03-01',
    status: true,
    classes: ['2409A'],

    studentCount: 76
  }
];

// 模拟API调用获取辅导员数据
export const getCounselors = async (): Promise<Counselor[]> => {
  // 模拟网络延迟
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve(mockCounselorData);
    }, 300);
  });
};

// 模拟API调用添加辅导员
export const addCounselor = async (counselor: Omit<Counselor, 'id'>): Promise<Counselor> => {
  return new Promise((resolve) => {
    setTimeout(() => {
      const newCounselor: Counselor = {
        ...counselor,
        id: mockCounselorData.length + 1
      };
      mockCounselorData.push(newCounselor);
      resolve(newCounselor);
    }, 300);
  });
};

// 模拟API调用更新辅导员
export const updateCounselor = async (id: number, counselor: Partial<Counselor>): Promise<Counselor> => {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      const index = mockCounselorData.findIndex(item => item.id === id);
      if (index === -1) {
        reject(new Error('辅导员不存在'));
        return;
      }
      mockCounselorData[index] = {
        ...mockCounselorData[index],
        ...counselor
      };
      resolve(mockCounselorData[index]);
    }, 300);
  });
};

// 模拟API调用删除辅导员
export const deleteCounselor = async (id: number): Promise<boolean> => {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      const index = mockCounselorData.findIndex(item => item.id === id);
      if (index === -1) {
        reject(new Error('辅导员不存在'));
        return;
      }
      mockCounselorData.splice(index, 1);
      resolve(true);
    }, 300);
  });
};